/*=========================================================================
 *
 *  Copyright NumFOCUS
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         https://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/
#ifndef itkQuadEdgeMeshPoint_hxx
#define itkQuadEdgeMeshPoint_hxx


namespace itk
{
// ---------------------------------------------------------------------
// ResetEdge would be a better name than Initialize.
template <typename TCoordinate, unsigned int VPointDimension, typename TQuadEdge>
void
QuadEdgeMeshPoint<TCoordinate, VPointDimension, TQuadEdge>::Initialize()
{
  m_Edge = static_cast<TQuadEdge *>(nullptr);
}


// ---------------------------------------------------------------------
template <typename TCoordinate, unsigned int VPointDimension, typename TQuadEdge>
QuadEdgeMeshPoint<TCoordinate, VPointDimension, TQuadEdge>::QuadEdgeMeshPoint(const Superclass & r)
  : Superclass(r)
{
  this->Initialize();
}

// ---------------------------------------------------------------------
template <typename TCoordinate, unsigned int VPointDimension, typename TQuadEdge>
QuadEdgeMeshPoint<TCoordinate, VPointDimension, TQuadEdge> &
QuadEdgeMeshPoint<TCoordinate, VPointDimension, TQuadEdge>::operator=(const Superclass & r)
{
  this->Superclass::operator=(r);
  this->Initialize();
  return (*this);
}

// ---------------------------------------------------------------------
template <typename TCoordinate, unsigned int VPointDimension, typename TQuadEdge>
QuadEdgeMeshPoint<TCoordinate, VPointDimension, TQuadEdge> &
QuadEdgeMeshPoint<TCoordinate, VPointDimension, TQuadEdge>::operator=(const ValueType r[VPointDimension])
{
  this->Superclass::operator=(r);
  this->Initialize();
  return (*this);
}

template <typename TCoordinate, unsigned int VPointDimension, typename TQuadEdge>
bool
QuadEdgeMeshPoint<TCoordinate, VPointDimension, TQuadEdge>::IsInternal() const
{
  if (this->GetEdge())
  {
    return this->GetEdge()->IsOriginInternal();
  }
  return false;
}

/** Return the valence of this QuadEdgeMeshPoint i.e. the number of edges constituting
 *  the Onext ring to which this point belongs.
 *  @return the valence when an entry in the Onext ring is present,
 *          and -1 otherwise.
 */
template <typename TCoordinate, unsigned int VPointDimension, typename TQuadEdge>
int
QuadEdgeMeshPoint<TCoordinate, VPointDimension, TQuadEdge>::GetValence() const
{
  int valence = -1; // error code by default

  if (this->GetEdge())
  {
    valence = this->GetEdge()->GetOrder();
  }

  return valence;
}

/** Set Edge
 *
 */
template <typename TCoordinate, unsigned int VPointDimension, typename TQuadEdge>
void
QuadEdgeMeshPoint<TCoordinate, VPointDimension, TQuadEdge>::SetEdge(TQuadEdge * inputEdge)
{
  m_Edge = inputEdge;
}

/** Get Edge
 *
 */
template <typename TCoordinate, unsigned int VPointDimension, typename TQuadEdge>
TQuadEdge *
QuadEdgeMeshPoint<TCoordinate, VPointDimension, TQuadEdge>::GetEdge() const
{
  return m_Edge;
}

/** Get Edge non-const version
 *
 */
template <typename TCoordinate, unsigned int VPointDimension, typename TQuadEdge>
TQuadEdge *
QuadEdgeMeshPoint<TCoordinate, VPointDimension, TQuadEdge>::GetEdge()
{
  return (m_Edge);
}

/** Set Point Coordinates
 *
 */
template <typename TCoordinate, unsigned int VPointDimension, typename TQuadEdge>
void
QuadEdgeMeshPoint<TCoordinate, VPointDimension, TQuadEdge>::SetPoint(const Superclass & point)
{
  this->Superclass::operator=(point);
}
} // namespace itk

#endif
